package com.virtual.repository.common.model;

import java.io.Serializable;

import javax.xml.bind.annotation.XmlAccessType;
import javax.xml.bind.annotation.XmlAccessorType;
import javax.xml.bind.annotation.XmlAttribute;
import javax.xml.bind.annotation.XmlIDREF;
import javax.xml.bind.annotation.XmlRootElement;

/**
 * Class representing the <strong>property</strong> element from configuration file, which
 * is placed inside <strong>mapping</strong> element.  
 * It stores information about single object's property, needed to map its between Java and source database.
 * 
 * @author kchaber
 */
@XmlAccessorType(XmlAccessType.NONE)
@XmlRootElement(name = "property")
public class Property implements Serializable {
	private static final long serialVersionUID = -6040591998530201174L;

	/**
	 * The name of the property in Java class.
	 */
	@XmlAttribute
	private String name;
	
	/**
	 * The fully qualified class name of the object containing this property.
	 */
	@XmlAttribute(name = "class")
	private String className;
	
	/**
	 * The name of the entity's property in source database.
	 */
	@XmlAttribute(name = "source-name")
	private String sourceName; 
	
	/**
	 * Field indicates whether property is foreign key property
	 */
	@XmlAttribute(name = "primary-key")
	private boolean primaryKey;
	
	/**
	 * The name of the foreign key
	 */
	@XmlAttribute(name = "foreign-key")
	private String foreignKey;
	
	/**
	 * The <code>DataSource</code> object. Indicates the database where the mapped property will be stored.
	 */
	@XmlIDREF
	@XmlAttribute(name = "data-source")
	private DataSource dataSource;

	public String getName() {
		return name;
	}

	public void setName(String name) {
		this.name = name;
	}

	public String getClassName() {
		return className;
	}

	public void setClassName(String className) {
		this.className = className;
	}

	public String getSourceName() {
		return sourceName;
	}

	public void setSourceName(String sourceName) {
		this.sourceName = sourceName;
	}

	public DataSource getDataSource() {
		return dataSource;
	}

	public void setDataSource(DataSource dataSource) {
		this.dataSource = dataSource;
	}

	public boolean isPrimaryKey() {
		return primaryKey;
	}

	public void setPrimaryKey(boolean primaryKey) {
		this.primaryKey = primaryKey;
	}

	public String getForeignKey() {
		return foreignKey;
	}

	public void setForeignKey(String foreignKey) {
		this.foreignKey = foreignKey;
	}

	@Override
	public String toString() {
		StringBuilder builder = new StringBuilder();
		builder.append("Property [name=");
		builder.append(name);
		builder.append(", className=");
		builder.append(className);
		builder.append(", sourceName=");
		builder.append(sourceName);
		builder.append(", primaryKey=");
		builder.append(primaryKey);
		builder.append(", foreignKey=");
		builder.append(foreignKey);
		builder.append(", dataSource=");
		builder.append(dataSource);
		builder.append("]");
		return builder.toString();
	}

}
